package com.recommendation.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.recommendation.taobao.TaobaoProxy;
import com.taobao.api.ApiException;
import com.taobao.api.domain.Item;
import com.taobao.api.response.ItemsOnsaleGetResponse;
import com.taobao.api.response.ShopRemainshowcaseGetResponse;

@Results({
	  @Result(location="showcases.jsp")
})
public class ShowcasesAction extends ActionBase{

	private long allCount;
	private long usedCount;
	private List<Item> items;
	
	public String execute()
	{
		String session = getSessionId();
		try {
			ShopRemainshowcaseGetResponse remainRsp = TaobaoProxy.getRemainShowCaseCount(session);
			if (remainRsp.isSuccess())
			{
				setAllCount(remainRsp.getShop().getAllCount());
				setUsedCount(remainRsp.getShop().getUsedCount());
			}
			else
			{
				error(remainRsp);
			}
			ItemsOnsaleGetResponse rsp = TaobaoProxy.getHasShowcaseItems(session, 100, "asc");
			if (rsp.isSuccess())
			{
				items = rsp.getItems();
			}
			else
			{
				error(rsp);
			}
		} catch (ApiException e) {
			error(e);
		}
		return SUCCESS;
	}

	public void setItems(List<Item> items) {
		this.items = items;
	}

	public List<Item> getItems() {
		return items;
	}

	public void setAllCount(long allCount) {
		this.allCount = allCount;
	}

	public long getAllCount() {
		return allCount;
	}

	public void setUsedCount(long usedCount) {
		this.usedCount = usedCount;
	}

	public long getUsedCount() {
		return usedCount;
	}
}
